<?php
 require_once("../config/index.php");
 require_once('../controllers/flag.php');
 require_once('../controllers/controller.php');
?>
  <!DOCTYPE html>
  <html lang="en">

  <head>
    <title></title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="<?php echo SERVER_STATICS?>css/stone.min.css" rel="stylesheet">
    <link href="<?php echo SERVER_STATICS?>css/bootstrap.min.css" rel="stylesheet">
    <style>
    body{
      background-image:url("<?php echo SERVER_STATICS?>img/index.jpg");
      color:white;
    }
    .info{
      width:40%;
      padding-top:140px;
    }
    #main{
      margin-top:100px;
    }
    li{
      margin-bottom:20px;
      font-size:19px;
    }
    h1{
      margin-top:40px;
    }
    .loginOut{
      position:fixed;
      top:10px;
      right:20px;
      color:skyBlue;
    }
    </style>
  </head>

  <body>
  <div class="container">
    <h1 class="tc">学生技能展示平台</h1>
    <div class="info l">
      <ul>
        <li>学生姓名：<?=$_SESSION['studentName']?></li>
        <li>学生ID：<?=$_SESSION['studentId']?></li>      
      </ul>
    </div>
    <div id="main" class="l" style="height:520px;width:520px;"></div>
  </div>
  <div class="loginOut"><a href="/studentSkill/controllers/controller.php?action=loginOut">退出登陆</a></div>

  </body>
  <script src="<?php echo SERVER_STATICS?>js/echarts.min.js"></script>
  <script>
    <?php
          $studentId=$_SESSION['studentId'];
          $res=$course->showAllInfoByStudent($studentId);
    ?>
    var dataSet=<?php echo json_encode($res)?>;
    var math=0;
    var mathCount=0;
    var skill=0;
    var skillCount=0;
    var practice=0;
    var practiceCount=0;
    var foreign=0;
    var foreignCount=0;    
    var culture=0
    var cultureCount=0;
    var body=0;
    var bodyCount=0;
    

    for(var i in dataSet){
      var t=JSON.parse(dataSet[i]);
      switch (t.kind) {
        case '数理水平':
          math=parseFloat(t.courseScore)*parseFloat(t.weight)+math;
          mathCount++;
          break;
        case '专业技能':
          skill=parseFloat(t.courseScore)*parseFloat(t.weight)+skill;
          skillCount++;
          break;
        case '动手实践':
          practice=parseFloat(t.courseScore)*parseFloat(t.weight)+practice;
          practiceCount++;
          break;
        case '外语水平':
          foreign=parseFloat(t.courseScore)*parseFloat(t.weight)+foreign;
          foreignCount++;
          break;
        case '文化素养':
          culture=parseFloat(t.courseScore)*parseFloat(t.weight)+culture;
          cultureCount++;
          break;
        case '身体素质':
          body=parseFloat(t.courseScore)*parseFloat(t.weight)+body;
          bodyCount++;
          break;
      
        default:
          break;
      }
    }

    var resArr=[math/mathCount||0,skill/skillCount||0,practice/practiceCount||0,foreign/foreignCount||0,culture/cultureCount||0,body/bodyCount||0];


    var myChart = echarts.init(document.getElementById('main'));
    var option = {
    title: {
      text: '',
    },
    tooltip: {},
    legend: {
      data: ['学生技能展示']
    },
    radar: { 
      // shape: 'circle',
      indicator: [{
        name: '数理水平',
        max: 100
      }, {
        name: '专业技能',
        max: 100
      }, {
        name: '动手实践',
        max: 100
      }, {
        name: '外语水平',
        max: 100
      }, {
        name: '文化素养',
        max: 100
      }, {
        name: '身体素质',
        max: 100
      }]
    },
    series: [{
        name: '学生技能',
        type: 'radar', 
        // areaStyle: {normal: {}}, 
        data: [{ value: resArr,name: ''}]
    }]
    };

    // 为echarts对象加载数据 
    myChart.setOption(option);
  </script>

  </html>